import * as actionTypes from '../constants/index'

const initState = {
  isAuth:false, //初始化没有登录
  msg:'',
  redirectTo:'',  
  edit:true
}

const user = (state = initState, action) => {
  switch(action.type) {
    case actionTypes.LOGIN:
      return {...state,isAuth:true,redirectTo:action.redirectTo}
    case actionTypes.LOGOUT:
      return {...initState,isAuth:false,redirectTo:'/login'}
    case actionTypes.ERROR_MSG:
      return {...state,isAuth:false,msg:action.msg}
    case actionTypes.LOAD_DATA:
      return {...state,...action.payload}
    case actionTypes.CLEAR_MSG:
      return {...state,msg:''}
    default:
      return state
  }
}

export { user }